# Maintainer: Wu Zhenyu <wuzy01@qq.com>
_realname=bottom

pkgbase=mingw-w64-$_realname
pkgname=$MINGW_PACKAGE_PREFIX-$_realname
pkgver=0.7.1
pkgrel=1
pkgdesc="A graphical process/system monitor (mingw-w64)"
url="https://github.com/ClementTsang/bottom"
arch=(any)
mingw_arch=(mingw32 mingw64 ucrt64 clang64)
license=('MIT')
makedepends=($MINGW_PACKAGE_PREFIX-rust tree)
source=("$url/archive/$pkgver/$_realname-$pkgver.tar.gz"
        "$url/releases/download/$pkgver/completion.tar.gz"
        "$url/releases/download/$pkgver/manpage.tar.gz")
sha256sums=('9d92688cceabac54ac47b7edcea3f858931b8f69661afb0d11dddc0bad5d3584'
            '7c166e22c18d61ff2b3a624c86a698238326bc905e965c01114fce73457c5bf7'
            '534985ee5c83f115d1c446fda7527b611eb892d230fd371ae041db639b10d906')

prepare() {
  cd "$_realname-$pkgver"
  cargo fetch --locked
}

build() {
  cd "$_realname-$pkgver"
  cargo build --frozen --release --all-features
}

check() {
  cd "$_realname-$pkgver"
  CARGO_HUSKY_DONT_INSTALL_HOOKS=true cargo test --frozen --all-features
}

package() {
  cd "$_realname-$pkgver"

  # binary
  install -vDm755 -t "$pkgdir$MINGW_PREFIX/bin" target/release/btm

  # license
  install -vDm644 -t "$pkgdir$MINGW_PREFIX/share/licenses/$_realname" LICENSE

  # documentation
  install -vDm644 -t "$pkgdir$MINGW_PREFIX/share/doc/$_realname" *.md
  cp -r docs sample_configs "$pkgdir$MINGW_PREFIX/share/doc/$_realname"
  rm "$pkgdir$MINGW_PREFIX/share/doc/bottom/docs/.gitignore"

  cd "${srcdir}"
  # manpage
  install -Dm644 btm.1.gz "$pkgdir$MINGW_PREFIX/share/man/man1/btm.1.gz"

  # completions
  install -Dm644 _btm "$pkgdir$MINGW_PREFIX/share/zsh/site-functions/_btm"
  install -Dm644 btm.bash "$pkgdir$MINGW_PREFIX/share/bash-completion/completions/btm"
  install -Dm644 btm.fish "$pkgdir$MINGW_PREFIX/share/fish/vendor_completions.d/btm.fish"
}
